package com.tshopping.dao;

import com.tshopping.bean.Order;
import org.apache.ibatis.annotations.*;
import org.aspectj.weaver.ast.Or;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;


@Repository
public interface OrderDao {

    @Insert("insert into orders(total,time,address,store,user) values(#{total},#{time},#{address},#{store},#{user})")
    @Options(useGeneratedKeys = true, keyColumn = "id")
    boolean insertOrderByAllOrderData(Order order);

    @Update("update orders set isFinish=#{isFinish} where id=#{id}")
    boolean updateIsFinishById(@Param("isFinish") int isFinish, @Param("id") int id);

    @Update("update orders set isPay=#{isPay} where id=#{id}")
    boolean updateIsPayById(@Param("isPay") int isPay, @Param("id") int id);

    @Update("update orders set isSendOut=#{isSendOut} where id=#{id}")
    boolean updateIsSendOutById(@Param("isSendOut") int isSendOut, @Param("id") int id);

    @Update("update orders set isReceive=#{isReceive} where id=#{id}")
    boolean updateIsReceiveById(@Param("isReceive") int isReceive, @Param("id") int id);

    @Update("update orders set isRefund=#{isRefund} where id=#{id}")
    boolean updateIsRefundById(@Param("isRefund") int isPay, @Param("id") int id);

    @Update("update orders set isFinishRefund=#{isFinishRefund} where id=#{id}")
    boolean updateIsFinishRefundById(@Param("isFinishRefund") int isFinishRefund, @Param("id") int id);

    @Update("update orders set isCommented=#{isCommented} where id=#{id}")
    boolean updateIsCommentedById(@Param("isCommented") int isCommented, @Param("id") int id);

    @Select("select * from orders where user=#{user} limit #{start},#{size}")
    ArrayList<Order> selectOrderByUserID(@Param("user") int user, @Param("start") int start, @Param("size") int size);

    @Select("select * from orders where store=#{store} limit #{start},#{size}")
    ArrayList<Order> selectOrderByStoreId(@Param("store") int store, @Param("start") int start, @Param("size") int size);

    @Select("select count(*) from orders where user=#{user}")
    int selectOrderCountByUser(@Param("user") int user);

    @Select("select count(*) from orders where store=#{store}")
    int selectOrderCountByStore(@Param("store") int store);

    @Update("update orders set address=#{address} where id=#{id}")
    boolean updateOrderAddressById(@Param("address") int address, @Param("id") int id);

    @Select("select count(*) from orders where user=#{user} and goods=#{goods} and isFinish=0")
    int selectOrderCountByUserAndGoods(@Param("user") int user, @Param("goods") int goods);

    @Select("select * from orders where id=#{id}")
    Order selectOrderById(@Param("id") int id);

}
